<template>
<div>
 <!--  http://piao.qunar.com/touch/ -->
  <homeheader></homeheader>
  <homeswiper :list="swiperlist"></homeswiper>
  <homeicons :list="iconlist"></homeicons>
  <homerecommend :list="recommendlist"></homerecommend>
  <homeweekend :list="weekendlist"></homeweekend>
</div>
</template>

<script>
import homeheader from './components/homeheader'
import homeswiper from './components/homeswiper'
import homeicons  from './components/homeicons'
import homerecommend from './components/homerecommend'
import homeweekend from './components/homeweekend'
import axios from 'axios'
import {mapState} from 'vuex'
export default {
  name: 'Home',
  components:{
    homeheader,
    homeswiper,
    homeicons,
    homerecommend,
    homeweekend,
  },
  data() {
    return {
     swiperlist:[],
     iconlist:[],
     recommendlist:[],
     weekendlist:[],
     lastcity:"",
    }
  },
  computed:{
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo(){
      axios.get('api/index.json?city='+ this.city)
      .then(this.ajaxsucc)
    },
    ajaxsucc(msg){
      if (msg.data.ret) {
       // console.log(msg)
        const data = msg.data.data
        this.swiperlist=data.swiperlist
        this.iconlist=data.iconlist
        this.recommendlist=data.recommendlist
        this.weekendlist=data.weekendlist

      }
    }
  },
  mounted() {
    this.lastcity=this.city
    this.getHomeInfo()
  },
  activated(){     //当页面 重新被显示 的时候执行
    if (this.lastcity!==this.city) {
      this.lastcity=this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style>

</style>


